import { reqBannerList, reqCategoryList, reqFloorList } from "@/api";

const actions = {
  // context指的是获取某个dispatch
  add(context) {
    // commit指的是提交给mutations
    context.commit("Add");
  },

  // 学到了，如果只用其中一两个属性，直接解构
  async categoryList({ commit }) {
    // 请求服务器是异步的(多人请求)
    const result = await reqCategoryList();
    if (result.code === 200) {
      console.log(result.data);
      commit("CategoryList", result.data);
    }
  },

  async bannerList({ commit }) {
    const result = await reqBannerList();
   //  console.log(result);
    if (result.code == 200) {
      commit("BannerList", result.data);
    }
  },

  async floorsList({commit}) {
    const result = await reqFloorList();
    console.log(result);
    if(result.code==200){
       commit("FloorsList",result.data)
    }
  },
};

const mutations = {
  Add(state) {
    state.count++;
  },

  // 放到store中
  CategoryList(state, categoryList) {
    state.categoryList = categoryList;
  },

  BannerList(state, bannerList) {
    state.bannerList = bannerList;
  },

  FloorsList(state,floorsList){
    state.floorsList = floorsList
  }
};

// 会对state中的属性进行计算然后返回，有点像计算属性，目的是为了生成新的属性
const getters = {};

const state = {
  //  count:1
  categoryList: [],
  bannerList: [],
  floorsList:[]
};

export default {
  actions,
  mutations,
  getters,
  state,
};
